package collect;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;

/**
 * Map 集合
 * @author galen
 */
public class HashMapClass {
    public static void main(String[] args) {
        HashMap users = new HashMap();
        users.put("11", "张三");
        users.put("22", "李四");
        users.put("33", "王五");
        users.put("44", "赵六");

        System.out.println("******** 学生列表 ********");
        Iterator it = users.keySet().iterator();
        while(it.hasNext()) {
            Object key = it.next();
            Object val = users.get(key);
            System.out.println("学号：" + key + "，姓名:" + val);
        }

        Scanner input = new Scanner(System.in);
        System.out.println("请输入要删除的学号：");
        int num = input.nextInt();
        if (users.containsKey(String.valueOf(num))) {
             // 如果包含就删除
            users.remove(String.valueOf(num));
        } else {
            System.out.println("该学生不存在！");
        }

        System.out.println("******** 学生列表 ********");
        it = users.keySet().iterator();
        while (it.hasNext()) {
            Object key = it.next();
            Object val = users.get(key);
            System.out.println("学号：" + key + "，姓名：" + val);
        }

    }
}
